package com.advanced.date;

import java.util.*;

public class DateWork {

	public static void main(String[] args) {
		// 以下题目关于"今年",不能写成固定的,要动态获得

		// 0：输出今天的日期和周几，周几用汉字表示
		Calendar c = Calendar.getInstance();
		String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", };
		int weekNum = c.get(Calendar.DAY_OF_WEEK);
		System.out.println(
				String.format("%d年%d月%d日 ", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE))
						+ weeks[weekNum - 1]);

		// 1:一件商品生产日期是2017/7/12,保质期5年，算出失效日期
		c.set(2017, 7 - 1, 12);
		System.out.println(String.format("商品生产日期是:%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1,
				c.get(Calendar.DATE)));
		c.add(Calendar.YEAR, 5);
		System.out.println(String.format("商品失效日期是:%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1,
				c.get(Calendar.DATE) - 1));

		// 2:计算当前时间距“世界末日”已经过去了多少天（2012-12-21）
		c.set(2012, 12 - 1, 21);
		System.out.println(String.format("“世界末日”是:%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1,
				c.get(Calendar.DATE)));
		System.out.println(c.get(Calendar.DATE));
		Calendar today = Calendar.getInstance();
		long days = (today.getTimeInMillis() - c.getTimeInMillis()) / 1000 / 3600 / 24;
		System.out.println("当前时间距“世界末日”已经过去了" + days + "天!");

		// 3：输出今年的国庆节（10.1）是周几
		c.set(2020, 10 - 1, 1);
		System.out.println("今年的国庆节（10.1）是:" + weeks[c.get(Calendar.DAY_OF_WEEK) - 1]);

		// 4：输出今年的星期天都是几号
		c.set(2020, 1 - 1, 1);
		System.out.println(
				String.format("%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE)));
		System.out.println(c.get(Calendar.YEAR));

		while (c.get(Calendar.YEAR) == 2020) {
			if (c.get(Calendar.DAY_OF_WEEK) == 1) {
				System.out.println(String.format("%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1,
						c.get(Calendar.DATE)) + "是星期天");
			}
			c.add(Calendar.DATE, 1);
		}

		// 5:6月的第3个星期日是父亲节，由用户输入年份，算出该年的父亲节是哪一天
		Scanner input = new Scanner(System.in);
		System.out.print("6月的第3个星期日是父亲节，请输入要查询的年份：");
		int year = input.nextInt();
		c.set(year, 6 - 1, 1);
		for (int i = 1; i <= 3; c.add(Calendar.DATE, 1)) {
			if (c.get(Calendar.DAY_OF_WEEK) == 1) {
				i++;
			}
		}
		System.out.println(
				String.format("%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE) - 1)
						+ "是父亲节");

		// 6：学士后结业考试的时间是每月倒数第二个周六上午8点，输出今年的考试时间
		// ，用yyyy/MM/dd hh时 的格式输出

		/*
		 * 这题还没搞定 for (int i = 0; i < 12; i++) { c.set(2020, i, 1); while
		 * (!(c.get(Calendar.MONTH) == i)) { // c.getMaximum(Calendar.WEEK_OF_MONTH); if
		 * (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
		 * System.out.println(String.format("%d/%d/%d ", c.get(Calendar.YEAR),
		 * c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE)) + "8:00是今年的考试时间"); }
		 * c.add(Calendar.DATE, 1); }
		 * 
		 * }
		 */

		// 7：学士后月考是每月的第一个周六，输出今年的月考时间
		c.set(2020, 1 - 1, 1);
		for (int i = 0; i < 12; i++) {
			c.set(2020, i, 1);
			while (!(c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {

				c.add(Calendar.DATE, 1);
			}
			System.out.println(
					String.format("%d年%d月%d日", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE))
							+ "是今年的月考时间");

		}

	}

}
